﻿using Microsoft.AspNetCore.Mvc;
using System;

public class AjaxResult
{
    public string Message { get; set; }

    public object Data { get; set; }

    public bool IsSuccess { get; set; }

    public static JsonResult Success(string msg = "", object data = null)
    {
        AjaxResult result = new AjaxResult
        {
            IsSuccess = true,
            Message = msg,
            Data = data
        };
        return new JsonResult(result);
    }

    public static JsonResult Error(string msg = "", object data = null)
    {
        AjaxResult result = new AjaxResult()
        {
            Message = msg,
            IsSuccess = false,
            Data = data
        };
        return new JsonResult(result);
    }

    public static JsonResult Error(Exception ex)
    {
        return Error(ex.Message);
    }
}

